package com.springframework.bean;

import com.self.springframework.beans.factory.*;
import com.self.springframework.context.ApplicationContext;
import com.self.springframework.context.ApplicationContextAware;

public class UserService implements InitializingBean, DisposableBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, ApplicationContextAware {
    private String name;

    private UserDao userDao;
    private IUserDao iUserDao;

    private Integer id;

    public void queryUserInfo() {
        System.out.println("查询用户信息:  " + name);
        System.out.println(name);
        System.out.println(userDao);
        if (iUserDao!=null) iUserDao.queryUserName("zs");
    }

    public String getName() {
        return name;
    }

    public IUserDao getiUserDao() {
        return iUserDao;
    }

    public void setiUserDao(IUserDao iUserDao) {
        this.iUserDao = iUserDao;
    }

    public void setName(String name) {
        this.name = name;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "UserService{" +
                "name='" + name + '\'' +
                ", userDao=" + userDao +
                ", id=" + id +
                '}';
    }

    @Override
    public void destroy() {
        System.out.println("生命周期结束,JVM关闭调用钩子函数");
    }

    @Override
    public void afterPropertiesSet() {
        System.out.println("初始化方法,Bean实例化属性填充之后调用初始化方法");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("Spring的类加载器:   " + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        System.out.println("Spring的Bean工厂:   " + beanFactory);
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("Spring中当前类的BeanName:   " + beanName);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        System.out.println("Spring的Application容器:   " + applicationContext);
    }
}
